package thread1;

import java.util.concurrent.*;

public class futureExceptionDemo1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 20, 20, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
        executor.execute(() -> {
            System.out.println("ccc");
        });
        Future<String> submit = executor.submit(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
                return "ddd";
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        System.out.println(submit.isDone());
        String string = submit.get();
        System.out.println(submit.isDone());

        Future<String> submit1 = executor.submit(() -> {
            throw new RuntimeException("mock exception");
        });

       try{
           submit1.get();
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }

        executor.shutdown();
    }
}
